package com.adl.telawa;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.widget.Toast;

/**
 * @author Adlane Achab.
 */
public class PhoneState extends BroadcastReceiver
{
	@Override
	public void onReceive(Context context, Intent intent) {
		Bundle bundle = null;
		if(null == (bundle = intent.getExtras()))
			return;

		final String state = bundle.getString(TelephonyManager.EXTRA_STATE);
		if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING))
		{
      try
      {
        if (Initial.INSTANCE._streamer.isPlaying() == true)
        {
          Initial.INSTANCE._streamer.pause();
          String info = "Incoming call, Telawa paused.";
          Toast.makeText(context, info, Toast.LENGTH_LONG).show();
        }
      }
      catch (Throwable e) {e.printStackTrace();}
		}	  
	}
}
